home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / biz / swood / FWTabTools.lha / FWTabTools / FWTableFormat.rexx < prev    next >
OS/2 REXX Batch file  |  1998-01-04  |  11KB  |  508 lines

  1. /* $VER: 0.14 , (04.01.1998), © by Thorsten Willert
  2.    
  3.    Macro um FinalWriter Tabelleninhalte zu formatieren
  4. -------------------------------------------------------*/
  5.  
  6. ADDRESS = 'FinaW'
  7. OPTIONS CACHE RESULTS
  8.  
  9. STATUS PORTNAME
  10. FW = RESULT
  11. ADDRESS = FW
  12.  
  13. SIGNAL ON BREAK_C
  14. SIGNAL ON HALT
  15. SIGNAL ON SYNTAX
  16.  
  17. /*-----------------------------------------------*/
  18.  
  19. RT.Version   = "Version 0.14"
  20. RT.Title     = "FWTableFormat"
  21. RT.Para1     = "rt_pubscrname = FinalWriterPubScreen rt_topoffset = 50 rt_reqpos = reqpos_topleftwin"
  22. RT.Copyright = "© 1997-98, by Thorsten Willert"
  23.  
  24. R = '0A'X
  25.  
  26. Format.Style = "NORMAL"
  27. Format.Justify = "LEFT"
  28. Format.Text2 = "\N \A M=1"
  29.  
  30. /*-----------------------------------------------*/
  31.  
  32. IF ~show('L',"rexxreqtools.library") THEN DO
  33.    IF ~addlib('rexxreqtools.library',0,-30,0) THEN DO
  34.       'ShowMessage 1 1 "Error ..." "Missing rexxreqtools.library!" "" "Exit !!" "" ""'
  35.       EXIT 20
  36.    END
  37. END
  38.  
  39. IF EXISTS("ENVARC:FWTableFormat.prefs") THEN
  40.     DO
  41.         IF OPEN(File,"ENVARC:FWTableFormat.prefs","R") THEN Format.Text2 = READLN(File)
  42.         CLOSE( File )
  43.     END
  44.  
  45.  
  46. DO FOREVER
  47.  
  48.     IF Info("_Formatieren|_Reset|_Hilfe|_Ende" ) == 0 THEN LEAVE
  49.     ELSE  IF GetCursor() = 1 THEN
  50.         DO
  51.             Func = RowCol()
  52.             IF Func = 1 THEN
  53.                 DO
  54.                     CALL GetCursor()
  55.                     CALL FormatiereCR
  56.                     CALL SetOldCursor
  57.                 END
  58.             ELSE IF Func = 2 THEN
  59.                 DO
  60.                     CALL GetCursor()
  61.                     CALL FormatiereC
  62.                     CALL SetOldCursor
  63.                 END
  64.             ELSE IF Func = 3 THEN
  65.                 DO
  66.                     CALL GetCursor()
  67.                     CALL FormatiereR
  68.                     CALL SetOldCursor
  69.                 END
  70.         END
  71.     ReDraw
  72.     
  73. END
  74.  
  75. /*-----------------------------------------------*/
  76.  
  77. Ende:
  78.  
  79. IF OPEN( File ,"ENVARC:FWTableFormat.prefs","W" ) THEN
  80.     WRITELN( File , Format.Text2 )
  81. CLOSE( File )
  82.  
  83. EXIT
  84.  
  85. /*-----------------------------------------------*/
  86.  
  87. RowCol:
  88.  
  89. RoCo = rtezrequest("Formatieren:","_Alles|_Spalte|_Zeile|_Zurück",RT.Title)
  90.  
  91. RETURN RoCo
  92.  
  93. /*-----------------------------------------------*/
  94.  
  95. GetCursor:
  96.  
  97. RESULT=""
  98.  
  99. ADDRESS(FW)
  100. TableGetActiveCell
  101. PARSE VAR RESULT Zeile Spalte
  102.  
  103. OldZeile = Zeile
  104. OldSpalte = Spalte
  105.  
  106. IF Zeile = "" | Spalte = "" THEN /* Geht nicht über GetObjektType */
  107.     DO
  108.         CALL KeineTabelle
  109.         RETURN 0
  110.     END
  111.  
  112. TableGetRows
  113. PARSE VAR RESULT Muell Zeilen
  114.  
  115. TableGetColumns
  116. PARSE VAR RESULT Muell Spalten
  117.  
  118. RETURN 1
  119.  
  120. /*-----------------------------------------------*/
  121.  
  122. SetOldCursor:
  123.  
  124. TableSetActiveCell OldZeile OldSpalte
  125.  
  126. RETURN
  127.  
  128. /*-----------------------------------------------*/
  129.  
  130. FormatiereC:
  131.  
  132. ADDRESS (FW)
  133.  
  134. i = 1
  135.  
  136. DO FOREVER
  137.     TableSetActiveCell Zeile Spalte
  138.         CALL Format
  139.     IF Zeile=Zeilen THEN LEAVE
  140.     Zeile=Zeile+1
  141.     i = i + 1
  142. END
  143.  
  144. Redraw
  145.     
  146. RETURN
  147.  
  148. /*-----------------------------------------------*/
  149.  
  150. FormatiereR:
  151.  
  152. ADDRESS (FW)
  153.  
  154. i = 1
  155.  
  156. DO FOREVER
  157.     TableSetActiveCell Zeile Spalte
  158.         CALL Format
  159.     IF Spalte=Spalten THEN LEAVE
  160.     Spalte=Spalte+1
  161.     i = i + 1
  162. END
  163.  
  164. Redraw
  165.     
  166. RETURN
  167.  
  168. /*-----------------------------------------------*/
  169.  
  170. FormatiereCR:
  171.  
  172. i = 0
  173.  
  174. OldZeile= Zeile
  175.  
  176. DO FOREVER
  177.     Zeile = OldZeile
  178.     TableSetActiveCell Zeile Spalte
  179.     CALL Format          
  180.         DO FOREVER
  181.             TableSetActiveCell Zeile Spalte
  182.             CALL Format
  183.             IF Zeile>=Zeilen THEN LEAVE
  184.             Zeile=Zeile+1
  185.         END 
  186.     IF Spalte>=Spalten THEN LEAVE
  187.     Spalte=Spalte+1
  188. END
  189.  
  190. RETURN
  191.  
  192. /*-----------------------------------------------*/
  193.  
  194. Format:
  195.  
  196. ADDRESS(FW)
  197.  
  198. IF Format.Copy ~= "" THEN Type Format.Copy
  199.  
  200. IF Func ~= 1 THEN
  201.     DO
  202.         IF Format.Count=1 THEN
  203.            DO
  204.                IF Format.Copy ~= "" THEN Type '20'X i
  205.                ELSE Type i '20'X
  206.            END
  207.         
  208.         IF Format.CountA=1 & i <= 27 THEN
  209.            DO
  210.                IF Format.Copy ~= "" THEN TYPE Type '20'X D2C(i+64)
  211.                ELSE Type D2C(i+64) '20'X
  212.            END
  213.         ELSE Format.CountA = 0
  214.     END    
  215.  
  216.  
  217. SelectAll
  218. Extract
  219. Text = TRANSLATE( STRIP( RESULT , "T" , '0A'X ),".",",")
  220.  
  221. IF Format.Auto = "AUTO" THEN
  222.     DO
  223.         Style Format.Style
  224.         
  225.         IF Format.Color ~= "" THEN FontColor Format.Color
  226.         IF Format.Font ~= "" THEN Font Format.Font
  227.         IF Format.Size ~= "" THEN FontSize Format.Size
  228.         
  229.         IF DATATYPE( Text , "NUMERIC" ) THEN Format.Justify = "RIGHT"
  230.         ELSE Format.Justify = "LEFT"
  231.         
  232.         CALL Margin(Format.Margin)
  233.        
  234.         Style Format.Style
  235.         Justify Format.Justify
  236.     END
  237. ELSE
  238.     DO    
  239.         CALL Margin(Format.Margin)
  240.         IF Format.Clear = 1 THEN Clear
  241.         Style Format.Style
  242.         Justify Format.Justify
  243.         IF Format.Color ~= "" THEN FontColor Format.Color
  244.         IF Format.Font ~= "" THEN Font Format.Font
  245.         IF Format.Size ~= "" THEN FontSize Format.Size
  246.     END
  247.  
  248. RETURN
  249.  
  250. /*-----------------------------------------------*/
  251.  
  252. Margin: PROCEDURE EXPOSE Format. FW
  253. PARSE ARG Rand
  254.  
  255. IF Format.Justify = "LEFT" THEN 
  256.     DO
  257.         SelectAll
  258.         Extract
  259.         Text = RESULT
  260.         Text = STRIP(Text)
  261.         Text = STRIP(Text,"T",'0A'X)
  262.         Clear
  263.         Type Text
  264.         IF Rand > 0 THEN
  265.             DO
  266.                 AltDown
  267.                 Cursor Left
  268.                 Type COPIES(" ",Rand)
  269.             END
  270.     END
  271. IF Format.Justify = "RIGHT" THEN
  272.     DO
  273.         Rand = 0.1 * Rand
  274.         ADDRESS(FW)
  275.         RightMargin Rand
  276.     END
  277.  
  278. RETURN
  279.  
  280. /*-----------------------------------------------*/
  281.  
  282. KeineTabelle:
  283.  
  284. rtezrequest("Zuerst eine Tabelle auswählen"||R||,
  285.             "und Cursor positioniern!","_Weiter",RT.Title)
  286.  
  287. RETURN
  288.  
  289. /*-----------------------------------------------*/
  290.  
  291. Info:
  292. PARSE ARG Taste1
  293.  
  294. IF Format.Text2 ~= "" THEN Format.Text = STRIP(Format.Text2)
  295.  
  296. DO FOREVER
  297.     res = rtgetstring(Format.Text,RT.Version||","||R||RT.Copyright,RT.Title,Taste1,RT.Para1)
  298.     IF rtresult = 2 THEN Format.Text = "\N \A M=1"
  299.     ELSE IF rtresult = 3 THEN CALL Hilfe
  300.     ELSE IF rtresult = 1 THEN LEAVE
  301.     ELSE RETURN rtresult
  302. END
  303.  
  304. CALL SelectFormat(res)
  305.  
  306. RETURN rtresult
  307.  
  308. /*------------------------------------------------*/
  309.  
  310. SelectFormat: PROCEDURE EXPOSE Format. 
  311. PARSE ARG A
  312.  
  313. res = UPPER(A)
  314. Format.Text2 = ""
  315.  
  316. SELECT                   
  317.     WHEN FIND( res, "\N" ) >= 1  THEN 
  318.         DO
  319.             Format.Style = "NORMAL"
  320.             Format.Text2 = Format.Text2 "\N"
  321.         END
  322.     WHEN FIND( res, "\U" ) >= 1  THEN
  323.         DO
  324.             Format.Style = "UNDERLINE"
  325.             Format.Text2 = Format.Text2 "\U"
  326.         END
  327.     WHEN FIND( res, "\DU" ) >= 1 THEN
  328.         DO
  329.             Format.Style = "DUNDERLINE"
  330.             Format.Text2 = Format.Text2 "\DU"
  331.         END
  332.     WHEN FIND( res, "\S" ) >= 1  THEN
  333.         DO 
  334.             Format.Style = "STRIKETHRU"
  335.             Format.Text2 = Format.Text2 "\S"
  336.         END
  337.     WHEN FIND( res, "\B" ) >= 1  THEN
  338.         DO
  339.             Format.Style = "BOLD"
  340.             Format.Text2 = Format.Text2 "\B"
  341.         END
  342.     WHEN FIND( res, "\I" ) >= 1  THEN
  343.         DO
  344.             Format.Style = "ITALIC"
  345.             Format.Text2 = Format.Text2 "\I"
  346.         END
  347.     OTHERWISE Format.Style = ""
  348. END
  349.  
  350. SELECT
  351.     WHEN FIND( res, "\L" ) >= 1 THEN
  352.         DO
  353.             Format.Justify = "LEFT"
  354.             Format.Text2 = Format.Text2 "\L"
  355.             Format.Auto = ""
  356.         END
  357.     WHEN FIND( res, "\C" ) >= 1 THEN
  358.         DO
  359.             Format.Justify = "CENTER"
  360.             Format.Text2 = Format.Text2 "\C"
  361.             Format.Auto = ""
  362.         END
  363.     WHEN FIND( res, "\R" ) >= 1 THEN
  364.         DO
  365.             Format.Justify = "RIGHT"
  366.             Format.Text2 = Format.Text2 "\R"
  367.             Format.Auto = ""
  368.         END
  369.     WHEN FIND( res , "\A" ) >= 1 THEN
  370.         DO
  371.             Format.Auto = "AUTO"
  372.             Format.Text2 = Format.Text2 "\A"
  373.         END
  374.     OTHERWISE
  375.         DO
  376.             Format.Justify = ""
  377.             Format.Auto = ""
  378.         END
  379. END
  380.  
  381. res = TRANSLATE(res, " ", "=" )
  382.  
  383. SizePos  = FIND( res, "SIZE" )
  384. FontPos  = FIND( res, "FONT")
  385. MPos     = FIND( res, "M")
  386. CountPos = FIND( res, "COUNT")
  387. CountAPos= FIND( res, "COUNTA")
  388. ClZ      = FIND( res, "CLEAR")
  389. CopyPos  = FIND( res, "COPY")
  390. ColorPos = FIND( res, "COLOR")
  391.  
  392.  
  393. IF SizePos >= 1 THEN
  394.     DO
  395.         Format.Size = SUBWORD( res,SizePos+1,1)
  396.         IF Format.Size <= 4 | DATATYPE( Format.Size,"WHOLE") = 0 THEN Format.Size = 4
  397.         Format.Text2 = Format.Text2 "SIZE="||Format.Size
  398.     END
  399. ELSE Format.Size = ""
  400.     
  401. IF FontPos >= 1 THEN
  402.     DO
  403.         Format.Font = SUBWORD( res,FontPos+1,1)
  404.         IF Format.Font ~= "" THEN Format.Font = Format.Font
  405.         Format.Text2 = Format.Text2 "FONT="||Format.Font
  406.     END
  407. ELSE Format.Font = ""
  408.     
  409. IF ColorPos >= 1 THEN
  410.     DO
  411.         Format.Color = SUBWORD( res,ColorPos+1,1)
  412.         IF Format.Color ~= "" THEN Format.Color = Format.Color
  413.         Format.Text2 = Format.Text2 'COLOR='||Format.Color
  414.     END
  415. ELSE Format.Color = ""
  416.  
  417.    
  418. IF MPos >= 1 THEN 
  419.     DO
  420.         Format.Margin = SUBWORD( res, MPos+1,1)
  421.         IF DATATYPE( Format.Margin , "WHOLE") = 0 THEN Format.Margin = 0
  422.         Format.Text2 = Format.Text2 "M="||Format.Margin
  423.     END
  424. ELSE Format.Margin = 0
  425.  
  426.  
  427. IF CountPos >= 1 THEN 
  428.     DO
  429.         Format.Count = 1
  430.         Format.Text2 = Format.Text2 "COUNT"
  431.     END
  432. ELSE Format.Count = 0
  433.  
  434.  
  435. IF CountAPos >= 1 THEN 
  436.     DO
  437.         Format.CountA = 1
  438.         Format.Text2 = Format.Text2 "COUNTA"
  439.     END
  440. ELSE Format.CountA = 0
  441.  
  442.     
  443. IF ClZ >= 1 THEN 
  444.     DO
  445.         Format.Clear = 1
  446.         Format.Text2 = Format.Text2 "CLEAR"
  447.     END
  448. ELSE Format.Clear = 0
  449.  
  450.  
  451. IF CopyPos >= 1 THEN
  452.     DO
  453.         Text = TRANSLATE(A, " ", "=" )
  454.  
  455.         Format.Copy = SUBWORD( Text,CopyPos+1)
  456.         PARSE ARG Format.Copy '"'Format.Copy'"'
  457.  
  458.         Format.Text2 = Format.Text2 'COPY="'||Format.Copy||'"'
  459.     END
  460. ELSE Format.Copy = ""
  461.  
  462.             
  463. RETURN res
  464.  
  465. /*-----------------------------------------------*/
  466.  
  467. Hilfe:
  468.  
  469. rtezrequest("Formatiert Zellen ab Cursorposition:"||R||R||,
  470.                "\N      = Normal"||R||,
  471.                "\U      = Unterstrichen"||R||,
  472.                "\DU     = Doppelt unterstrichen"||R||,
  473.                "\S      = Durchgestrichen"||R||,
  474.                "\B      = Bold"||R||,
  475.                "\I      = Italic"||R||,
  476.                "\L      = Links justiert"||R||,
  477.                "\C      = Zentriert"||R||,
  478.                "\R      = Rechts justiert"||R||,
  479.                "\A      = Auto-Justierung (Text links, Zahlen Rechts)"||R||,
  480.                "M=X     = Rand (nur mit Justierung wirksam)"||R||,
  481.                "SIZE=X  = Schriftgröße"||R||,
  482.                "FONT=X  = Schriftname"||R||,
  483.                "COLOR=X = Schriftfarbe"||R||,
  484.                "COUNT   = Nummerierung"||R||,
  485.                "COUNTA  = Alphabetische Nummerierung"||R||,
  486.                "CLEAR   = Inhalt löschen"||R||,
  487.                "COPY=X  = Mit X ausfüllen (! letztes Argument)","_Aha",RT.Title)
  488.  
  489.  
  490. RETURN
  491.  
  492. /*-----------------------------------------------*/
  493.  
  494. HALT:
  495. BREAK_C:
  496.  
  497. rtezrequest("Macro wurde abgebrochen ... ","_Weiter",RT.Title)
  498.  
  499. EXIT 10
  500.  
  501. /*-----------------------------------------------*/
  502.  
  503. SYNTAX:
  504.  
  505. rtezrequest("Fehler!","_Weiter|_Hilfe",RT.Title)
  506. IF rtresult == 0 THEN CALL Hilfe
  507.  
  508. EXIT 10